<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn" xml:lang="zh-cn">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>编辑文章分类</title>
  <?=HTML::style ('styles/admin/stylesheet.css')?>
  <?=HTML::script('scripts/admin/jquery/jquery-1.7.2.min.js')?>
  <?=HTML::script('scripts/admin/jquery/jquery.form.js')?>
</head>

<body>
<div id="container">
  <div class="box" style="margin:0 5px 0 15px;">
    <div class="heading">
      <h1>编辑文章分类</h1>
      <div class="buttons" style="padding-top:12px;"><a href="<?=URL::site('admin/article')?>?cat_id=<?=$cat_id?>" target="_parent">文章列表</a></div>
    </div>
    <div class="content">
      <form method="post" enctype="multipart/form-data" id="form" onsubmit="return ajax_post();">
        <table class="form">
          <tr>
            <td width="120">上级分类</td>
            <td><span class="cats_select"><img src="<?=URL::site()?>images/admin/ajax-loading.gif" align="absbottom" /> <font color="gray">数据加载中…</font></span></td>
          </tr>
          <tr>
            <td>分类名称 <span class="required">*</span></td>
            <td><input type="text" size="60" maxlength="50" name="name" value="<?=$name?>" /> <font color="gray">不允许包含标点符号及特殊字符，字符长度：2~50</font></td>
          </tr>
          <tr>
            <td>排序</td>
            <td><input type="text" size="5"  maxlength="5" name="sort_order" value="<?=$sort_order?>" /></td>
          </tr>
          <tr>
            <td>是否显示</td>
            <td>
            <label><input type="radio" name="is_show" value="1" <?=$is_show?'checked':''?> /> 显示</label> &nbsp;
            <label><input type="radio" name="is_show" value="0" <?=$is_show?'':'checked'?> /> 隐藏</label> &nbsp;
            </td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><input type="button" onclick="ajax_post();" class="btn70" value="保存修改" /> &nbsp;
            <input type="button" onclick="ajax_del(<?=$cat_id?>)" class="btn70" value="删除分类" /></td>
          </tr>
        </table>
      </form>
    </div>
  </div>
</div>
</body>
</html>
<?=HTML::script('admin/article_category/js')?>
<script type="text/javascript">
$().ready(function(){
    $('.cats_select').html(category_select_reverse(<?=$parent_id?>, 'parent_id', function(obj, cat){
        if (obj.value == <?=$cat_id?>) {
            alert('不能选择自身做为上级分类！');
            obj.value = cat.parent_id;
            return false;
        }
        return true;
    }));
});

function ajax_post() {
    $.ajax({
        url      : document.location.href,
        type     : 'post',
        data     : $('#form').serialize(),
        dataType : 'html',
        cache    : false,
        redirect : false,
        error    : function(XMLHttpRequest, textStatus, errorThrown){
            alert('发生错误：' + (errorThrown?errorThrown:textStatus));
        },
        success  : function(html) {
            if ($.trim(html).length > 0) {
                alert(html);
            } else {
                alert('编辑分类操作成功！');
                parent.frames.treeFrame.location.reload();
                location = '<?=URL::site('admin/article_category/add')?>';
            }
        }
    });
    return false;
}

function ajax_del(id) {
    if (confirm('确认要删除该分类吗?')) {
        $.ajax({
            url      : '<?=URL::site('admin/article_category/del')?>/' + id,
            type     : 'get',
            dataType : 'html',
            cache    : false,
            redirect : false,
            error    : function(XMLHttpRequest, textStatus, errorThrown){
                alert('发生错误：' + (errorThrown?errorThrown:textStatus));
            },
            success  : function(html){
                if ($.trim(html).length > 0) {
                    alert(html);
                } else {
                    alert('文章分类删除成功！');
                    parent.frames.treeFrame.location.reload();
                    location.href = '<?=URL::site('admin/article_category/add')?>';
                }
            }
        });
        return false;

    }
    return false;
}
</script>